
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class pgsqltest2 {
	public Connection getConnect() {
		Connection con = null;
		try {
			Class.forName("org.postgresql.Driver");
			con = DriverManager.getConnection("jdbc:postgresql://chow.vicp.cc:25432/postgres", "postgres", "123456Aa");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return con;
	}

	Thread[] threads = new Thread[3];
	StringBuffer sb = new StringBuffer(1024 * 1024);

	public void todo() throws SQLException {
		try(Connection con = getConnect()){
			for (int k = 0; k < threads.length; k++) {
				threads[k] = new Thread(new Runnable() {
					@Override
					public void run() {
	
						try {
							Statement st = con.createStatement();
							ResultSet resultSet = st.executeQuery(
									"SELECT data_sharding_id, db_id, pod_id, idc_id, subtab_id, \"version\", status\r\n"
											+ "FROM gp_dbm_rel limit 100");
							while (resultSet.next()) {
								// 取出列值
								String id = resultSet.getString(1);
								String name = resultSet.getString(2);
								System.out.println(Thread.currentThread().getName() + " > " + id + "," + name);
								double t = Math.random();
								Thread.sleep((long) ((t * 10) % 10));
							}
	
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
	
				});
				threads[k].start();
			}

			for (int k = 0; k < threads.length; k++) {
				try {
					threads[k].join();
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}

	public static void main(String[] args) throws Exception {
		pgsqltest2 ti = new pgsqltest2();
		ti.todo();
	}
}